<template>
  <nav class="bottom-tab-bar">
    <div v-for="item in tabs" :key="item.name || ''" :class="['tab-item', {active: (route && route.name) === item.routeName}]" @click="go(item.routeName)">
      <el-icon :size="24"><component :is="item.icon" /></el-icon>
      <span>{{ item.label }}</span>
      <div v-if="(route && route.name) === item.routeName" class="tab-active-bar"></div>
    </div>
  </nav>
</template>

<script setup>
import { useRouter, useRoute } from 'vue-router'
import { House, User, ShoppingCart, Guide, Trophy } from '@element-plus/icons-vue'

const router = useRouter()
const route = useRoute()
const tabs = [
  { name: '首页', label: '首页', icon: House, routeName: 'home' },
  { name: '教练', label: '教练', icon: Guide, routeName: 'coach' },
  { name: '运动', label: '运动', icon: Trophy, routeName: 'sport' },
  { name: '商城', label: '商城', icon: ShoppingCart, routeName: 'shop' },
  { name: '我的', label: '我的', icon: User, routeName: 'user' },
]
function go(name) {
  router.push({ name })
}
</script>

<style scoped>
.bottom-tab-bar {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100vw;
  height: 60px;
  background: #fff;
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -2px 8px #f0f1f2;
  z-index: 100;
  border-radius: 18px 18px 0 0;
  border-top: 1.5px solid #f0f0f0;
}
.tab-item {
  flex: 1;
  text-align: center;
  color: #888;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 2px 0 0 0;
  transition: color 0.2s, font-weight 0.2s;
  position: relative;
  height: 100%;
}
.tab-item.active {
  color: #00b96b;
  font-weight: 700;
}
.tab-item .el-icon {
  margin-bottom: 2px;
}
.tab-item .tab-active-bar {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 3px;
  background: #00b96b;
  border-radius: 2px;
}
.tab-item span {
  margin-top: 2px;
  font-size: 13px;
}
</style> 